#include <iostream>
#include <string>

int const maxn = 52;
int const opt[2][2] = {{1, 1}, {1, -1}};
std::string da[maxn];
int n, m;

bool inrange(int x, int y)
{
	return (0 <= x && x < n) && (0 <= y && y < m);
}

int main()
{
	std::ios::sync_with_stdio(false);
	int T;
	std::cin >> T;
	while (T--) {
		std::cin >> n;
		for (int i = 0; i < n; i++)
			std::cin >> da[i];
		m = da[0].size();

		int red = 0;
		for (int i = n-1; i >= 0; i--) {
			int x = i, y = 0;
			do {
				while (inrange(x, y) && (da[x][y] == 'B' || da[x][y] == '.')) {
					x += opt[0][0]; y += opt[0][1];
				}
				if (inrange(x, y) && (da[x][y] == 'R' || da[x][y] == 'G')) {
					red++;
					while (inrange(x, y) && (da[x][y] == 'R' || da[x][y] == 'G')) {
						x += opt[0][0]; y += opt[0][1];
					}
				}
			} while (inrange(x, y));
		}
		for (int i = 1; i < m; i++) {
			int x = 0, y = i;
			do {
				while (inrange(x, y) && (da[x][y] == 'B' || da[x][y] == '.')) {
					x += opt[0][0]; y += opt[0][1];
				}
				if (inrange(x, y) && (da[x][y] == 'R' || da[x][y] == 'G')) {
					red++;
					while (inrange(x, y) && (da[x][y] == 'R' || da[x][y] == 'G')) {
						x += opt[0][0]; y += opt[0][1];
					}
				}
			} while (inrange(x, y));
		}


		int blue = 0;
		for (int i = 0; i < m; i++) {
			int x = 0, y = i;
			do {
				while (inrange(x, y) && (da[x][y] == 'R' || da[x][y] == '.')) {
					x += opt[1][0]; y += opt[1][1];
				}
				if (inrange(x, y) && (da[x][y] == 'B' || da[x][y] == 'G')) {
					blue++;
					while (inrange(x, y) && (da[x][y] == 'B' || da[x][y] == 'G')) {
						x += opt[1][0]; y += opt[1][1];
					}
				}
			} while (inrange(x, y));
		}
		for (int i = 1; i < n; i++) {
			int x = i, y = m-1;
			do {
				while (inrange(x, y) && (da[x][y] == 'R' || da[x][y] == '.')) {
					x += opt[1][0]; y += opt[1][1];
				}
				if (inrange(x, y) && (da[x][y] == 'B' || da[x][y] == 'G')) {
					blue++;
					while (inrange(x, y) && (da[x][y] == 'B' || da[x][y] == 'G')) {
						x += opt[1][0]; y += opt[1][1];
					}
				}
			} while (inrange(x, y));
		}

		std::cout << red + blue << '\n';
	}
}

